package com.yiang.hotel.controller;

import com.yiang.base.R;
import com.yiang.feign.OrderClient;
import com.yiang.hotel.entity.Hotel;
import com.yiang.hotel.service.HotelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "酒店服务")
@RestController
@Slf4j
public class HotelController {
    @Value("${server.port}")
    private String port;
    @Autowired
    private HotelService hotelService;
    @Autowired
    private OrderClient orderClient;

    @GetMapping("/test")
    @Operation(summary = "测试接口")
    @Cacheable(cacheNames = "Hotels", key = "'test'")  //key和方法名对应 加''
    public void test() {
        List<Hotel> list = hotelService.list();
        System.out.println(list);
    }

    /**
     * 新增
     * @param hotel
     * @return
     */
    @PostMapping("/saveHotel")
    @Cacheable(cacheNames = "hotel", key = "#hotel.name")
    public R saveHotel(@RequestBody Hotel hotel) {
        // 名字不得为空
        // return R.fail("名字不得为空");
        return R.success("新增酒店成功");
    }

    @GetMapping("/getOrder")
    public String getOrder() {
        return orderClient.getOrder();
    }
}
